C++Data StructuresAlgorithmsCompetitive ProgrammingJavaPythonMicroprocessorsGraph TheoryComputer System ArchitectureMachine LearningArtificial IntelligenceData Structures in PythonJavascriptMySQLAndroid DevelopmentAlgorithms in PythonCoding InterviewData ScienceData Structures in JavaObject Oriented DesignLinked ListBinary Trees

Linked List

Reverse Linked List

Swap Nodes in Pairs

Problem Link: LeetCode 206. Reverse Linked List


class Solution {
    public ListNode reverseList(ListNode head) {
        ListNode prev = null;
        ListNode cur = head;
        while(cur != null){
            ListNode temp = cur.next;
            cur.next = prev;
            prev = cur;
            cur = temp;
        }
        return prev;
    }
}